set varabbrev off
set more off
cap log close
set mem 500m
clear

/*------[Matrix Start]------*/
set obs 12
forval i= 1(1)7{							
gen Spalte`i' = .
mkmat Spalte`i'
}
mkmat Spalte1 Spalte2 - Spalte7, matrix(matrixd)   

drop Spalte*
/*------[Matrix End]------*/

use "filepath\Uganda_shortterm.dta", clear





gen variable_0=age
gen variable_1=hhsize
gen variable_2=female
gen variable_3=completed_primary
gen variable_4=ownaccount
gen variable_5=lagcapcr






 
gen rt_versus_c=.
replace rt_versus_c=1 if control==1
replace rt_versus_c=0 if rulethumb==1

gen p_versus_c=.
replace p_versus_c=1 if control==1
replace p_versus_c=0 if personalized==1


foreach num of numlist 0(1)5 {

local num2=2*`num'+1
sum variable_`num' if wave==8

matrix matrixd[`num2',1]=`r(N)'
matrix matrixd[`num2',2]=round(`r(mean)',.01)
matrix matrixd[`num2'+1,2]=round(`r(sd)',.01)


sum variable_`num' if wave==8 & control==1
matrix matrixd[`num2',3]=round(`r(mean)',.01)
matrix matrixd[`num2'+1,3]=round(`r(sd)',.01)

sum variable_`num' if wave==8 & rulethumb==1
matrix matrixd[`num2',4]=round(`r(mean)',.01)
matrix matrixd[`num2'+1,4]=round(`r(sd)',.01)

ttest variable_`num' if wave==8 , by(rt_versus_c)
local diff=round(`r(mu_1)'-`r(mu_2)',.01)
matrix matrixd[`num2',5]=round(`diff',.01)
matrix matrixd[`num2'+1,5]=round(`r(p)',.01)


sum variable_`num' if wave==8 & personalized==1
matrix matrixd[`num2',6]=round(`r(mean)',.01)
matrix matrixd[`num2'+1,6]=round(`r(sd)',.01)


ttest variable_`num' if wave==8 , by(p_versus_c)
local diff=round(`r(mu_1)'-`r(mu_2)',.01)
matrix matrixd[`num2',7]=round(`diff',.01)
matrix matrixd[`num2'+1,7]=round(`r(p)',.01)


}

matrix list matrixd

matrix rownames matrixd =  Age _ HH_size _ Female _ Higher_education _ Own-account_ _  Capital_stock_ _ 

matrix list matrixd
outtable using ${DESC_PATH}/desc_vT2PA, mat(matrixd)  replace f(%9.0g %9.2fc %9.2fc %9.2fc %9.2fc  %9.2fc %9.2fc )



